package org.kealinghornets.nxtdroid;

import org.kealinghornets.nxtdroid.NXT.LightSensor;
import org.kealinghornets.nxtdroid.NXT.NXTThread;
import org.kealinghornets.nxtdroid.NXT.TouchSensor;

/**
 * Created by jychuah on 11/3/13.
 */
public class MyNXTThread extends NXTThread {

    int state = 1;
    LightSensor eyeball;

    public MyNXTThread() {
        setNXTThreadName("Bridge Crosser");
    }

    public void run() {
        while (state != -1) {
            switch(state) {
                case 1 : do_state_1(); break;
                case 2 : do_state_2(); break;
                case 3 : do_state_3(); break;
                case 5 : do_state_5(); break;
                case 6 : do_state_6(); break;
                case 7 : do_state_7(); break;
                case 8 : do_state_8(); break:
                case 9 : do_state_9(); break;
                default : state = -1; break;
            }
        }
    }

    public void do_state_1() {
        eyeball = getActiveLightSensor(PORT_1);

        log("I am going forward and read my sensor");
        runMotor(PORT_A,-90);
        runMotor(PORT_B, 90);
                     if (eyeball.getLightValue() > 500) {
            state = 2;
        } else {
            state = 3;
        }

    }

    public void do_state_2() {
        log ("I am going forward again and turning left");
        runMotor(PORT_A,PORT_B);
        wait(300);
            runMotor(PORT_A,-90);
            runMotor(PORT_B, 90);
        state = 4;
    }

    public void do_state_3() {
        log ("I am turning right, and reading my sensor in state 3");
            runMotor(PORT_A,-90);
            runMotor(PORT_B, 90);
        wait(300);
            getActiveLightSensor(PORT_1);
        if(lightValue<300);
            runMotor(PORT_A,PORT_B);
            wait(300);
        get lightSensor(PORT_1);
            if(lightValue<150)runmotor(PORT_A,180);
        state=5;
    }

    public void do_state_5() {
        log ("I am going forward");
        runMotor(PORT_A,PORT_B);
        wait(300);
        brakeMotor(PORT_A,PORT_B);
    }

    public void do_state_6() {
        log("I am going forward");
        runMotor(PORT_A,PORT_B);
        wait(300);
        brakeMotor(PORT_A,PORT_B);
    }

    public void do_state_7() {
        log("I am in state 7");
        runMotor(PORT_A, 90);
        runMotor(PORT_B,-90);
        brakeMotor(PORT_A,PORT_B);
    }

    public void do_state_8() {
        log("I am in state 8");
        runMotor(PORT_A, 90);
        runMotor(PORT_B,-90);
        brakeMotor(PORT_A,PORT_B);
    }

    public void do_state_9() {
        log("I am in state 9");
        runMotor(PORT_A,PORT_B);
        wait(300);
        brakeMotor(PORT_A,PORT_B);
    }

    public void do_state_10() {
        log("i am in state 10");
        runMotor(PORT_A,-90);
        runMotor(PORT_B, 90);
        brakeMotor(PORT_A,PORT_B);
    }

    public void do_state_11() {
        log("i am in state 11");
        runMotor(PORT_A,PORT_B);
        wait(200);
        brakeMotor(PORT_A,PORT_B);
    }

    public void do_state_12() {
        log("i am in state 12");
        runMotor(PORT_A, 90);
        runMotor(PORT_B,-90);
        brakeMotor(PORT_A,PORT_B);
    }

    public void do_state_13() {
        log("i am in state 13");
        runMotor(PORT_A,PORT_B);
        wait(200);
        if (eyeball.getLightValue() > 300);
        brakeMotor(PORT_A,PORT_B);
    }

    public void do_state_14() {
        log("i am in state 14");
        runMotor(PORT_A,PORT_B);
        int power(100);
        brakeMotor(PORT_A,PORT_B);
    }

    public void do_state_15() {
        log("");
    }



    public void do_state_16() {
        log("");

    }

    public void do_state_17() {
        log("i am in state 17");
        runMotor(PORT_A,PORT_B);
        wait(200);
        if (eyeball.getLightValue(lightValue<500));
        log("lightValue"+lightValue);
    }}
